/**
 * This file is part of gCoKe [ http://www.gcoke.org ]
 *
 * Copyright (C) 2010-  Sebastien Mosser
 *
 * gCoKe is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation; either version 2 of 
 * the License, or (at your option) any later version.
 *
 * gCoKe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with gCoke; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @author   Main    Sebastien Mosser  [ sm@gcoke.org ]
 **/
package org.gcoke.dsl.compiler;

import java.io.*;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;

public class ASTBuilder {

    public static GCoKeParser buildParser(InputStream input) throws Exception {
	ANTLRInputStream in = new ANTLRInputStream(input);
	GCoKeLexer lexer = new GCoKeLexer(in);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	GCoKeParser parser = new GCoKeParser(tokens);
	return parser;
    }

    public static CommonTree buildAST(GCoKeParser parser) throws Exception {
	GCoKeParser.source_return r = parser.source();
	CommonTree tree = (CommonTree) r.getTree();
	//System.out.println(tree.toStringTree()); // Grammar debug (kind of)
	return tree;
    }
    
    public static CommonTree run(InputStream input) throws Exception {
	return buildAST(buildParser(input));
    }

}